260372bfe6811ebae16c78947da1d7e2d9ec1f1b,testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ejb/container/interceptor/security/SwitchIdentityTestCase.java,SwitchIdentityTestCase,callUsingClientLoginModul,#String#boolean#boolean#,198

Before Change


    private void callUsingClientLoginModul(String userName, boolean hasRole1, boolean hasRole2) throws Exception {
        LoginContext loginContext = null;
        try {
            loginContext = new LoginContext("foo", new Subject(), new UsernamePasswordHandler(userName, new char[0]),
                    CLIENT_LOGIN_CONFIG);
            loginContext.login();

            // register the client side interceptor
            final EJBClientContext ejbClientContext = EJBClientContext.getCurrent().withAddedInterceptors(new ClientSecurityInterceptor());
            ejbClientContext.runCallable(() -> {
                final Manage targetBean = EJBUtil.lookupEJB(TargetBean.class, Manage.class);
                final Manage bridgeBean = EJBUtil.lookupEJB(BridgeBean.class, Manage.class);

                //test direct access
                testMethodAccess(targetBean, ManageMethodEnum.ALLROLES, true);
                testMethodAccess(targetBean, ManageMethodEnum.ROLE1, hasRole1);
                testMethodAccess(targetBean, ManageMethodEnum.ROLE2, hasRole2);

                //test security context propagation
                testMethodAccess(bridgeBean, ManageMethodEnum.ALLROLES, true);
                testMethodAccess(bridgeBean, ManageMethodEnum.ROLE1, hasRole1);
                testMethodAccess(bridgeBean, ManageMethodEnum.ROLE2, hasRole2);
                return null;
            });
        } finally {
            if (loginContext != null) {
                loginContext.logout();

After Change


    /**
     * Perform the tests using the ClientLoginModule and LoginContext API to set the desired Principal.
     */
    private void callUsingClientLoginModule(String userName, boolean hasRole1, boolean hasRole2) throws Exception {

        AuthenticationContext authenticationContext = setupAuthenticationContext(userName);
        authenticationContext.runCallable(() -> {

            // register the client side interceptor
            final EJBClientContext ejbClientContext = EJBClientContext.getCurrent().withAddedInterceptors(new ClientSecurityInterceptor());
            ejbClientContext.runCallable(() -> {
                final Manage targetBean = EJBUtil.lookupEJB(TargetBean.class, Manage.class);
                final Manage bridgeBean = EJBUtil.lookupEJB(BridgeBean.class, Manage.class);

                //test direct access
                testMethodAccess(targetBean, ManageMethodEnum.ALLROLES, true);
                testMethodAccess(targetBean, ManageMethodEnum.ROLE1, hasRole1);
                testMethodAccess(targetBean, ManageMethodEnum.ROLE2, hasRole2);

                //test security context propagation
                testMethodAccess(bridgeBean, ManageMethodEnum.ALLROLES, true);
                testMethodAccess(bridgeBean, ManageMethodEnum.ROLE1, hasRole1);
                testMethodAccess(bridgeBean, ManageMethodEnum.ROLE2, hasRole2);
                return null;
            });
            return null;
        });
    }

    private AuthenticationContext setupAuthenticationContext(final String username) {